<template>
	<view>
		<!-- //标题 -->
		<view class="top-box tn-cool-bg-color-15--reverse">
			<view class="text-lg margin-left-lg text-bold tn-cool-bg-color-15--reverse padding-xs">{{timeGet}}</view>
			<view class="text-lg text-bold">{{placename}}未送订单统计</view>
			<view class="text-lg margin-right-sm text-bold tn-cool-bg-color-15--reverse padding-xs"
				style="border-radius: 10rpx;" @click="shuaxin">刷新</view>
		</view>
		<view class="main-content" >
			<view  style="margin-top: 40rpx;margin-bottom: 10rpx;display: flex;justify-content: center;align-items: center;width: 100%;margin-top: 10rpx;height: 100%;">
				<view class="text-bold text-lg text-black margin-left-xs">时间</view>
				<view class="text-lg text-black text-bold margin-right-lg" style="flex: 1; text-align: end;">未送单量</view>
			</view>
		</view>
		<view class="main-content">
			<view v-for="(item,index) in timeList" :key="index" class="list" >
				<view
					style="display: flex;justify-content: center;align-items: center;width: 100%;margin-top: 10rpx;height: 100%;">
					<view class="text-lg text-bold margin-left-xs">{{item.time}}</view>
					<view class="text-red text-xxl text-bold margin-right-lg" style="flex: 1; text-align: end;">
						{{item.count}}</view>
				</view>
				<view style="width: 100%;display: flex;flex-direction: row;justify-content: space-around;">
					<view class="login__info__item__button tn-cool-bg-color-15--reverse" hover-class="tn-hover"
						:hover-stay-time="150"@click="toTimeSet(item.time)">商家统计</view>
					<!-- <view class="login__info__item__button tn-cool-bg-color-15--reverse" hover-class="tn-hover"
						:hover-stay-time="150" @click="goLou(item.name)">楼栋统计</view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	//时间
	//数据库引入
	const db = uniCloud.database();
	const dbCmd = db.command;
	//引入全局变量
	var app = getApp();
	export default {
		data() {
			return {
				timeGet: '',
				timeList: [],
				storeList: [],
				openid: "",
				place: 0,
				placename: "",
				school :-1
			}
		},
		onLoad(option) {
			let that = this;
			this.place = option.place
			var schoolName = ""
			this.school = Number(option.school)
			switch(this.school){
				case 0:{
					schoolName = '中南大学'
					break
				}
				case 1:{
					schoolName = '中南大学'
					break
				}
				case 2:{
					schoolName = '湖南大学财经'
					break
				}
			}
			if (this.place == 1) {
				this.placename = schoolName+"麓南区域"
			}
			if (this.place == 2) {
				this.placename = schoolName+"后湖区域"
			}else{
				this.placename = "财经区域"
			}
			
		},
		onShow() {
			let that = this;
			if (this.openid == "") {
				// this.checkLogin()
			}
			uni.request({
				url: "https://zback.shixiaozhu.work/ShixiaozhuTest/order/getQsForOutQs" +
					"?palce=" + that.place+"&oSchool="+that.school,
				success(res) {
					if (res.data.status == 200) {
						that.timeList = res.data.data
						// for (var i = 0; i < res.data.data.length; i++) {
						// 	that.timeList[i] = res.data.data[i].time
						// 	that.timeList[i].num = res.data.data[i].count
						// 	console.log("num",that.timeList[i].num)
						// }
					} else {
						uni.showToast({
							title: res.data.data
						})
					}
				}
			})
		},
		methods: {
			goLou(time) {
				uni.navigateTo({
					url: "outQsLouDetail?place="+this.place+"&timeGet="+time
				})
			},
			checkLogin() {
				let that = this;
				uni.getStorage({
					key: 'user_sxz',
					success: function(res) {
						that.openid = res.data.openid;
						that.userinfo = res.data.info;
						uni.request({
							url: "https://zback.shixiaozhu.work/ShixiaozhuTest/order/getQsForOutQs" +
								"?palce=" + that.place+"&oSchool="+that.school,
							success(res) {
								if (res.data.status == 200) {
									for (var i = 0; i < that.timeList.length; i++) {
										that.timeList[i].name = res.data.data[i].time
										that.timeList[i].num = res.data.data[i].count
										console.log("num",that.timeList[i].num)
									}
								} else {
									uni.showToast({
										title: res.data.data
									})
								}
							}
						})
					},
					fail() {
						// console.log('获取本地缓存失败！')
						uni.hideLoading();
						//那么就要去引导用户进行登陆了
						uni.showModal({
							title: '您还没有绑定微信登陆，是否要现在进行绑定？',
							success(res) {
								if (res.confirm) {
									//用户选择了登陆，直接跳转到登陆界面
									uni.switchTab({
										url: '../me/me'
									});
								}
							}
						});
					}
				});
			},
			shuaxin() {
				let that = this;
				//请求订单
				uni.request({
					url: "https://zback.shixiaozhu.work/ShixiaozhuTest/order/getQsForOutQs?openid=" + this.openid +
						"&palce=" + that.place+"&oSchool="+that.school,
					success(res) {
						if (res.data.status == 200) {
							for (var i = 0; i < that.timeList.length; i++) {
								that.timeList[i].name = res.data.data[i].time
								that.timeList[i].num = res.data.data[i].count
							}
						} else {
							uni.showToast({
								title: res.data.data
							})
						}
					}
				})
			},
			toTimeSet(time) {
				let place = this.place
				let that =this
				console.log('输出时间：', time);
				if(place==2){
					uni.navigateTo({
						url: "../manageArea/manageArea?timeGet=" + time +"&oSchool="+that.school+"&place="+place
					})
				}else{
					uni.navigateTo({
						url: "outQsTimeDetail?timeGive=" + time + "&place=" + place+"&oSchool="+that.school
					})
				}

				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login__info__item__button {
		width: 180rpx;
		padding: 10rpx;
		border-radius: 5px;
		text-align: center;
		font-size: 32rpx;
		font-weight: bold;
		justify-content: center;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.top-box {
		width: 100%;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.list1 {
		width: 100%;
		height: 100rpx;
		display: flex;
		flex-direction: row;
		flex-direction: column;
		border: 1rpx solid #e6e6e6;
		align-items: center;
		/* 		margin-bottom: 10rpx; */
		background-color: #ffffff;
	}

	.list {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		border: 1rpx solid #e6e6e6;
		align-items: center;
		/* 		margin-bottom: 10rpx; */
		background-color: #ffffff;
	}

	.menu-tem {
		box-sizing: border-box;
		flex: 0 0 33.33%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: 192rpx;
		border: 2px solid #000000;
	}

	.menu-item-text {
		font-size: 26rpx;
		margin-top: 10rpx;
		color: #333;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
</style>
